package com.wisnews.util;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

/**
 * @Description：验证码工具类
 * @Author: yuyd
 * @Email: yyd8358@foxmail.com
 * @Date: 2021/2/3 10:26
 * @Version 1.0
 */
public class AuthCodeUtil {

    private static String[] number = {"1","2","3","4","5","6","7","8","9","0"};
    /**
     * @description: 生成6位随机数字
     * @param:
     * @return:
     * @author yuyd
     * @date: 2021/5/4 21:31
     */
    public static String genRodomCode(){

        StringBuilder stringBuilder = new StringBuilder("");

        try {
            SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
            for (int i = 0; i < 6; i++) {
                int ran = random.nextInt(10);
                stringBuilder.append(number[ran]);
            }
        } catch (NoSuchAlgorithmException nsae) {
            nsae.printStackTrace();
        }

        return stringBuilder.toString();
    }
}
